package com.springbootquartz.Job_Test;

import lombok.SneakyThrows;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;

/**
 * @author rise
 * @date 2024年11月01日 14:22
 */
public class JobQuartzTest {
    @SneakyThrows
    public static void main(String[] args) {
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        scheduler.start();

//        JobDetail job = newJob(PlayGameJob.class)
//                .withIdentity("myJob", "group1")
//                .usingJobData("gameName", "GTA5")
//                .usingJobData("gamePrice", 55.5f)
//                .build();
//
//        Trigger trigger = newTrigger()
//                .withIdentity("myJob", "group1")
//                .build();
//
//        scheduler.scheduleJob(job, trigger);

        JobDetail job2 = newJob(PlayGameJob2.class)
                .storeDurably()
                .withIdentity("myJob", "group1")
                .usingJobData("gameName", "GTA5")
                .usingJobData("gamePrice", 55.0f)
                .build();
        SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInSeconds(1)
                .repeatForever();
        Trigger trigger2 = newTrigger()
                .withIdentity("myJob", "group1")
                .withSchedule(simpleScheduleBuilder)
                .build();

        scheduler.scheduleJob(job2, trigger2);

        Thread.sleep(10000);

        scheduler.shutdown();

    }
}
